// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PySelectionProperties.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PySelectionProperties
//
// Purpose:
//   Contains attributes for a selection
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a SelectionProperties.
//
struct SelectionPropertiesObject
{
    PyObject_HEAD
    SelectionProperties *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewSelectionProperties(int);
std::string
PySelectionProperties_ToString(const SelectionProperties *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    snprintf(tmpStr, 1000, "%sname = \"%s\"\n", prefix, atts->GetName().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%ssource = \"%s\"\n", prefix, atts->GetSource().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%shost = \"%s\"\n", prefix, atts->GetHost().c_str());
    str += tmpStr;
    const char *selectionType_names = "BasicSelection, CumulativeQuerySelection";
    switch (atts->GetSelectionType())
    {
      case SelectionProperties::BasicSelection:
          snprintf(tmpStr, 1000, "%sselectionType = %sBasicSelection  # %s\n", prefix, prefix, selectionType_names);
          str += tmpStr;
          break;
      case SelectionProperties::CumulativeQuerySelection:
          snprintf(tmpStr, 1000, "%sselectionType = %sCumulativeQuerySelection  # %s\n", prefix, prefix, selectionType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    const char *idVariableType_names = "UseZoneIDForID, UseGlobalZoneIDForID, UseLocationsForID, UseVariableForID";
    switch (atts->GetIdVariableType())
    {
      case SelectionProperties::UseZoneIDForID:
          snprintf(tmpStr, 1000, "%sidVariableType = %sUseZoneIDForID  # %s\n", prefix, prefix, idVariableType_names);
          str += tmpStr;
          break;
      case SelectionProperties::UseGlobalZoneIDForID:
          snprintf(tmpStr, 1000, "%sidVariableType = %sUseGlobalZoneIDForID  # %s\n", prefix, prefix, idVariableType_names);
          str += tmpStr;
          break;
      case SelectionProperties::UseLocationsForID:
          snprintf(tmpStr, 1000, "%sidVariableType = %sUseLocationsForID  # %s\n", prefix, prefix, idVariableType_names);
          str += tmpStr;
          break;
      case SelectionProperties::UseVariableForID:
          snprintf(tmpStr, 1000, "%sidVariableType = %sUseVariableForID  # %s\n", prefix, prefix, idVariableType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%sidVariable = \"%s\"\n", prefix, atts->GetIdVariable().c_str());
    str += tmpStr;
    {   const stringVector &variables = atts->GetVariables();
        snprintf(tmpStr, 1000, "%svariables = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < variables.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", variables[i].c_str());
            str += tmpStr;
            if(i < variables.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &variableMins = atts->GetVariableMins();
        snprintf(tmpStr, 1000, "%svariableMins = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < variableMins.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", variableMins[i]);
            str += tmpStr;
            if(i < variableMins.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &variableMaxs = atts->GetVariableMaxs();
        snprintf(tmpStr, 1000, "%svariableMaxs = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < variableMaxs.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", variableMaxs[i]);
            str += tmpStr;
            if(i < variableMaxs.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    snprintf(tmpStr, 1000, "%sminTimeState = %d\n", prefix, atts->GetMinTimeState());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaxTimeState = %d\n", prefix, atts->GetMaxTimeState());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%stimeStateStride = %d\n", prefix, atts->GetTimeStateStride());
    str += tmpStr;
    const char *combineRule_names = "CombineAnd, CombineOr";
    switch (atts->GetCombineRule())
    {
      case SelectionProperties::CombineAnd:
          snprintf(tmpStr, 1000, "%scombineRule = %sCombineAnd  # %s\n", prefix, prefix, combineRule_names);
          str += tmpStr;
          break;
      case SelectionProperties::CombineOr:
          snprintf(tmpStr, 1000, "%scombineRule = %sCombineOr  # %s\n", prefix, prefix, combineRule_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    const char *histogramType_names = "HistogramTime, HistogramMatches, HistogramID, HistogramVariable";
    switch (atts->GetHistogramType())
    {
      case SelectionProperties::HistogramTime:
          snprintf(tmpStr, 1000, "%shistogramType = %sHistogramTime  # %s\n", prefix, prefix, histogramType_names);
          str += tmpStr;
          break;
      case SelectionProperties::HistogramMatches:
          snprintf(tmpStr, 1000, "%shistogramType = %sHistogramMatches  # %s\n", prefix, prefix, histogramType_names);
          str += tmpStr;
          break;
      case SelectionProperties::HistogramID:
          snprintf(tmpStr, 1000, "%shistogramType = %sHistogramID  # %s\n", prefix, prefix, histogramType_names);
          str += tmpStr;
          break;
      case SelectionProperties::HistogramVariable:
          snprintf(tmpStr, 1000, "%shistogramType = %sHistogramVariable  # %s\n", prefix, prefix, histogramType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%shistogramNumBins = %d\n", prefix, atts->GetHistogramNumBins());
    str += tmpStr;
    if(atts->GetHistogramAutoScaleNumBins())
        snprintf(tmpStr, 1000, "%shistogramAutoScaleNumBins = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%shistogramAutoScaleNumBins = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%shistogramStartBin = %d\n", prefix, atts->GetHistogramStartBin());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%shistogramEndBin = %d\n", prefix, atts->GetHistogramEndBin());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%shistogramVariable = \"%s\"\n", prefix, atts->GetHistogramVariable().c_str());
    str += tmpStr;
    return str;
}

static PyObject *
SelectionProperties_Notify(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_SetName(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the name in the object.
    obj->data->SetName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetName(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetName().c_str());
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetSource(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the source in the object.
    obj->data->SetSource(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetSource(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetSource().c_str());
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetHost(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the host in the object.
    obj->data->SetHost(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetHost(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetHost().c_str());
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetSelectionType(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid selectionType value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " BasicSelection";
        ss << ", CumulativeQuerySelection";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the selectionType in the object.
    obj->data->SetSelectionType(SelectionProperties::SelectionType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetSelectionType(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetSelectionType()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetIdVariableType(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 4)
    {
        std::stringstream ss;
        ss << "An invalid idVariableType value was given." << std::endl;
        ss << "Valid values are in the range [0,3]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " UseZoneIDForID";
        ss << ", UseGlobalZoneIDForID";
        ss << ", UseLocationsForID";
        ss << ", UseVariableForID";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the idVariableType in the object.
    obj->data->SetIdVariableType(SelectionProperties::IDVariableType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetIdVariableType(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetIdVariableType()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetIdVariable(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the idVariable in the object.
    obj->data->SetIdVariable(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetIdVariable(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetIdVariable().c_str());
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetVariables(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetVariables() = vec;
    // Mark the variables in the object as modified.
    obj->data->SelectVariables();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetVariables(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    // Allocate a tuple the with enough entries to hold the variables.
    const stringVector &variables = obj->data->GetVariables();
    PyObject *retval = PyTuple_New(variables.size());
    for(size_t i = 0; i < variables.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(variables[i].c_str()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetVariableMins(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetVariableMins() = vec;
    // Mark the variableMins in the object as modified.
    obj->data->SelectVariableMins();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetVariableMins(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    // Allocate a tuple the with enough entries to hold the variableMins.
    const doubleVector &variableMins = obj->data->GetVariableMins();
    PyObject *retval = PyTuple_New(variableMins.size());
    for(size_t i = 0; i < variableMins.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(variableMins[i]));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetVariableMaxs(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetVariableMaxs() = vec;
    // Mark the variableMaxs in the object as modified.
    obj->data->SelectVariableMaxs();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetVariableMaxs(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    // Allocate a tuple the with enough entries to hold the variableMaxs.
    const doubleVector &variableMaxs = obj->data->GetVariableMaxs();
    PyObject *retval = PyTuple_New(variableMaxs.size());
    for(size_t i = 0; i < variableMaxs.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(variableMaxs[i]));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetMinTimeState(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the minTimeState in the object.
    obj->data->SetMinTimeState(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetMinTimeState(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetMinTimeState()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetMaxTimeState(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the maxTimeState in the object.
    obj->data->SetMaxTimeState(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetMaxTimeState(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetMaxTimeState()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetTimeStateStride(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the timeStateStride in the object.
    obj->data->SetTimeStateStride(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetTimeStateStride(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetTimeStateStride()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetCombineRule(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid combineRule value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " CombineAnd";
        ss << ", CombineOr";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the combineRule in the object.
    obj->data->SetCombineRule(SelectionProperties::CombinationType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetCombineRule(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetCombineRule()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetHistogramType(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 4)
    {
        std::stringstream ss;
        ss << "An invalid histogramType value was given." << std::endl;
        ss << "Valid values are in the range [0,3]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " HistogramTime";
        ss << ", HistogramMatches";
        ss << ", HistogramID";
        ss << ", HistogramVariable";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the histogramType in the object.
    obj->data->SetHistogramType(SelectionProperties::HistogramType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetHistogramType(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetHistogramType()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetHistogramNumBins(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the histogramNumBins in the object.
    obj->data->SetHistogramNumBins(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetHistogramNumBins(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetHistogramNumBins()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetHistogramAutoScaleNumBins(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the histogramAutoScaleNumBins in the object.
    obj->data->SetHistogramAutoScaleNumBins(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetHistogramAutoScaleNumBins(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetHistogramAutoScaleNumBins()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetHistogramStartBin(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the histogramStartBin in the object.
    obj->data->SetHistogramStartBin(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetHistogramStartBin(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetHistogramStartBin()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetHistogramEndBin(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the histogramEndBin in the object.
    obj->data->SetHistogramEndBin(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetHistogramEndBin(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetHistogramEndBin()));
    return retval;
}

/*static*/ PyObject *
SelectionProperties_SetHistogramVariable(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the histogramVariable in the object.
    obj->data->SetHistogramVariable(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SelectionProperties_GetHistogramVariable(PyObject *self, PyObject *args)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetHistogramVariable().c_str());
    return retval;
}



PyMethodDef PySelectionProperties_methods[SELECTIONPROPERTIES_NMETH] = {
    {"Notify", SelectionProperties_Notify, METH_VARARGS},
    {"SetName", SelectionProperties_SetName, METH_VARARGS},
    {"GetName", SelectionProperties_GetName, METH_VARARGS},
    {"SetSource", SelectionProperties_SetSource, METH_VARARGS},
    {"GetSource", SelectionProperties_GetSource, METH_VARARGS},
    {"SetHost", SelectionProperties_SetHost, METH_VARARGS},
    {"GetHost", SelectionProperties_GetHost, METH_VARARGS},
    {"SetSelectionType", SelectionProperties_SetSelectionType, METH_VARARGS},
    {"GetSelectionType", SelectionProperties_GetSelectionType, METH_VARARGS},
    {"SetIdVariableType", SelectionProperties_SetIdVariableType, METH_VARARGS},
    {"GetIdVariableType", SelectionProperties_GetIdVariableType, METH_VARARGS},
    {"SetIdVariable", SelectionProperties_SetIdVariable, METH_VARARGS},
    {"GetIdVariable", SelectionProperties_GetIdVariable, METH_VARARGS},
    {"SetVariables", SelectionProperties_SetVariables, METH_VARARGS},
    {"GetVariables", SelectionProperties_GetVariables, METH_VARARGS},
    {"SetVariableMins", SelectionProperties_SetVariableMins, METH_VARARGS},
    {"GetVariableMins", SelectionProperties_GetVariableMins, METH_VARARGS},
    {"SetVariableMaxs", SelectionProperties_SetVariableMaxs, METH_VARARGS},
    {"GetVariableMaxs", SelectionProperties_GetVariableMaxs, METH_VARARGS},
    {"SetMinTimeState", SelectionProperties_SetMinTimeState, METH_VARARGS},
    {"GetMinTimeState", SelectionProperties_GetMinTimeState, METH_VARARGS},
    {"SetMaxTimeState", SelectionProperties_SetMaxTimeState, METH_VARARGS},
    {"GetMaxTimeState", SelectionProperties_GetMaxTimeState, METH_VARARGS},
    {"SetTimeStateStride", SelectionProperties_SetTimeStateStride, METH_VARARGS},
    {"GetTimeStateStride", SelectionProperties_GetTimeStateStride, METH_VARARGS},
    {"SetCombineRule", SelectionProperties_SetCombineRule, METH_VARARGS},
    {"GetCombineRule", SelectionProperties_GetCombineRule, METH_VARARGS},
    {"SetHistogramType", SelectionProperties_SetHistogramType, METH_VARARGS},
    {"GetHistogramType", SelectionProperties_GetHistogramType, METH_VARARGS},
    {"SetHistogramNumBins", SelectionProperties_SetHistogramNumBins, METH_VARARGS},
    {"GetHistogramNumBins", SelectionProperties_GetHistogramNumBins, METH_VARARGS},
    {"SetHistogramAutoScaleNumBins", SelectionProperties_SetHistogramAutoScaleNumBins, METH_VARARGS},
    {"GetHistogramAutoScaleNumBins", SelectionProperties_GetHistogramAutoScaleNumBins, METH_VARARGS},
    {"SetHistogramStartBin", SelectionProperties_SetHistogramStartBin, METH_VARARGS},
    {"GetHistogramStartBin", SelectionProperties_GetHistogramStartBin, METH_VARARGS},
    {"SetHistogramEndBin", SelectionProperties_SetHistogramEndBin, METH_VARARGS},
    {"GetHistogramEndBin", SelectionProperties_GetHistogramEndBin, METH_VARARGS},
    {"SetHistogramVariable", SelectionProperties_SetHistogramVariable, METH_VARARGS},
    {"GetHistogramVariable", SelectionProperties_GetHistogramVariable, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
SelectionProperties_dealloc(PyObject *v)
{
   SelectionPropertiesObject *obj = (SelectionPropertiesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *SelectionProperties_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PySelectionProperties_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "name") == 0)
        return SelectionProperties_GetName(self, NULL);
    if(strcmp(name, "source") == 0)
        return SelectionProperties_GetSource(self, NULL);
    if(strcmp(name, "host") == 0)
        return SelectionProperties_GetHost(self, NULL);
    if(strcmp(name, "selectionType") == 0)
        return SelectionProperties_GetSelectionType(self, NULL);
    if(strcmp(name, "BasicSelection") == 0)
        return PyInt_FromLong(long(SelectionProperties::BasicSelection));
    if(strcmp(name, "CumulativeQuerySelection") == 0)
        return PyInt_FromLong(long(SelectionProperties::CumulativeQuerySelection));

    if(strcmp(name, "idVariableType") == 0)
        return SelectionProperties_GetIdVariableType(self, NULL);
    if(strcmp(name, "UseZoneIDForID") == 0)
        return PyInt_FromLong(long(SelectionProperties::UseZoneIDForID));
    if(strcmp(name, "UseGlobalZoneIDForID") == 0)
        return PyInt_FromLong(long(SelectionProperties::UseGlobalZoneIDForID));
    if(strcmp(name, "UseLocationsForID") == 0)
        return PyInt_FromLong(long(SelectionProperties::UseLocationsForID));
    if(strcmp(name, "UseVariableForID") == 0)
        return PyInt_FromLong(long(SelectionProperties::UseVariableForID));

    if(strcmp(name, "idVariable") == 0)
        return SelectionProperties_GetIdVariable(self, NULL);
    if(strcmp(name, "variables") == 0)
        return SelectionProperties_GetVariables(self, NULL);
    if(strcmp(name, "variableMins") == 0)
        return SelectionProperties_GetVariableMins(self, NULL);
    if(strcmp(name, "variableMaxs") == 0)
        return SelectionProperties_GetVariableMaxs(self, NULL);
    if(strcmp(name, "minTimeState") == 0)
        return SelectionProperties_GetMinTimeState(self, NULL);
    if(strcmp(name, "maxTimeState") == 0)
        return SelectionProperties_GetMaxTimeState(self, NULL);
    if(strcmp(name, "timeStateStride") == 0)
        return SelectionProperties_GetTimeStateStride(self, NULL);
    if(strcmp(name, "combineRule") == 0)
        return SelectionProperties_GetCombineRule(self, NULL);
    if(strcmp(name, "CombineAnd") == 0)
        return PyInt_FromLong(long(SelectionProperties::CombineAnd));
    if(strcmp(name, "CombineOr") == 0)
        return PyInt_FromLong(long(SelectionProperties::CombineOr));

    if(strcmp(name, "histogramType") == 0)
        return SelectionProperties_GetHistogramType(self, NULL);
    if(strcmp(name, "HistogramTime") == 0)
        return PyInt_FromLong(long(SelectionProperties::HistogramTime));
    if(strcmp(name, "HistogramMatches") == 0)
        return PyInt_FromLong(long(SelectionProperties::HistogramMatches));
    if(strcmp(name, "HistogramID") == 0)
        return PyInt_FromLong(long(SelectionProperties::HistogramID));
    if(strcmp(name, "HistogramVariable") == 0)
        return PyInt_FromLong(long(SelectionProperties::HistogramVariable));

    if(strcmp(name, "histogramNumBins") == 0)
        return SelectionProperties_GetHistogramNumBins(self, NULL);
    if(strcmp(name, "histogramAutoScaleNumBins") == 0)
        return SelectionProperties_GetHistogramAutoScaleNumBins(self, NULL);
    if(strcmp(name, "histogramStartBin") == 0)
        return SelectionProperties_GetHistogramStartBin(self, NULL);
    if(strcmp(name, "histogramEndBin") == 0)
        return SelectionProperties_GetHistogramEndBin(self, NULL);
    if(strcmp(name, "histogramVariable") == 0)
        return SelectionProperties_GetHistogramVariable(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PySelectionProperties_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PySelectionProperties_methods[i].ml_name),
                PyString_FromString(PySelectionProperties_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PySelectionProperties_methods, self, name);
}

int
PySelectionProperties_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "name") == 0)
        obj = SelectionProperties_SetName(self, args);
    else if(strcmp(name, "source") == 0)
        obj = SelectionProperties_SetSource(self, args);
    else if(strcmp(name, "host") == 0)
        obj = SelectionProperties_SetHost(self, args);
    else if(strcmp(name, "selectionType") == 0)
        obj = SelectionProperties_SetSelectionType(self, args);
    else if(strcmp(name, "idVariableType") == 0)
        obj = SelectionProperties_SetIdVariableType(self, args);
    else if(strcmp(name, "idVariable") == 0)
        obj = SelectionProperties_SetIdVariable(self, args);
    else if(strcmp(name, "variables") == 0)
        obj = SelectionProperties_SetVariables(self, args);
    else if(strcmp(name, "variableMins") == 0)
        obj = SelectionProperties_SetVariableMins(self, args);
    else if(strcmp(name, "variableMaxs") == 0)
        obj = SelectionProperties_SetVariableMaxs(self, args);
    else if(strcmp(name, "minTimeState") == 0)
        obj = SelectionProperties_SetMinTimeState(self, args);
    else if(strcmp(name, "maxTimeState") == 0)
        obj = SelectionProperties_SetMaxTimeState(self, args);
    else if(strcmp(name, "timeStateStride") == 0)
        obj = SelectionProperties_SetTimeStateStride(self, args);
    else if(strcmp(name, "combineRule") == 0)
        obj = SelectionProperties_SetCombineRule(self, args);
    else if(strcmp(name, "histogramType") == 0)
        obj = SelectionProperties_SetHistogramType(self, args);
    else if(strcmp(name, "histogramNumBins") == 0)
        obj = SelectionProperties_SetHistogramNumBins(self, args);
    else if(strcmp(name, "histogramAutoScaleNumBins") == 0)
        obj = SelectionProperties_SetHistogramAutoScaleNumBins(self, args);
    else if(strcmp(name, "histogramStartBin") == 0)
        obj = SelectionProperties_SetHistogramStartBin(self, args);
    else if(strcmp(name, "histogramEndBin") == 0)
        obj = SelectionProperties_SetHistogramEndBin(self, args);
    else if(strcmp(name, "histogramVariable") == 0)
        obj = SelectionProperties_SetHistogramVariable(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
SelectionProperties_print(PyObject *v, FILE *fp, int flags)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)v;
    fprintf(fp, "%s", PySelectionProperties_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
SelectionProperties_str(PyObject *v)
{
    SelectionPropertiesObject *obj = (SelectionPropertiesObject *)v;
    return PyString_FromString(PySelectionProperties_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *SelectionProperties_Purpose = "Contains attributes for a selection";
#else
static char *SelectionProperties_Purpose = "Contains attributes for a selection";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(SelectionPropertiesType,         \
                  "SelectionProperties",           \
                  SelectionPropertiesObject,       \
                  SelectionProperties_dealloc,     \
                  SelectionProperties_print,       \
                  PySelectionProperties_getattr,   \
                  PySelectionProperties_setattr,   \
                  SelectionProperties_str,         \
                  SelectionProperties_Purpose,     \
                  SelectionProperties_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
SelectionProperties_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &SelectionPropertiesType
         || Py_TYPE(other) != &SelectionPropertiesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    SelectionProperties *a = ((SelectionPropertiesObject *)self)->data;
    SelectionProperties *b = ((SelectionPropertiesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static SelectionProperties *defaultAtts = 0;
static SelectionProperties *currentAtts = 0;

static PyObject *
NewSelectionProperties(int useCurrent)
{
    SelectionPropertiesObject *newObject;
    newObject = PyObject_NEW(SelectionPropertiesObject, &SelectionPropertiesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new SelectionProperties(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new SelectionProperties(*defaultAtts);
    else
        newObject->data = new SelectionProperties;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapSelectionProperties(const SelectionProperties *attr)
{
    SelectionPropertiesObject *newObject;
    newObject = PyObject_NEW(SelectionPropertiesObject, &SelectionPropertiesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (SelectionProperties *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
SelectionProperties_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewSelectionProperties(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef SelectionPropertiesMethods[] = {
    {"SelectionProperties", SelectionProperties_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *SelectionPropertiesObserver = 0;

std::string
PySelectionProperties_GetLogString()
{
    std::string s("SelectionProperties = SelectionProperties()\n");
    if(currentAtts != 0)
        s += PySelectionProperties_ToString(currentAtts, "SelectionProperties.", true);
    return s;
}

static void
PySelectionProperties_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("SelectionProperties = SelectionProperties()\n");
        s += PySelectionProperties_ToString(currentAtts, "SelectionProperties.", true);
        cb(s);
    }
}

void
PySelectionProperties_StartUp(SelectionProperties *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PySelectionProperties_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(SelectionPropertiesObserver == 0)
    {
        SelectionPropertiesObserver = new ObserverToCallback(subj,
            PySelectionProperties_CallLogRoutine, (void *)data);
    }

}

void
PySelectionProperties_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete SelectionPropertiesObserver;
    SelectionPropertiesObserver = 0;
}

PyMethodDef *
PySelectionProperties_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return SelectionPropertiesMethods;
}

bool
PySelectionProperties_Check(PyObject *obj)
{
    return (obj->ob_type == &SelectionPropertiesType);
}

SelectionProperties *
PySelectionProperties_FromPyObject(PyObject *obj)
{
    SelectionPropertiesObject *obj2 = (SelectionPropertiesObject *)obj;
    return obj2->data;
}

PyObject *
PySelectionProperties_New()
{
    return NewSelectionProperties(0);
}

PyObject *
PySelectionProperties_Wrap(const SelectionProperties *attr)
{
    return WrapSelectionProperties(attr);
}

void
PySelectionProperties_SetParent(PyObject *obj, PyObject *parent)
{
    SelectionPropertiesObject *obj2 = (SelectionPropertiesObject *)obj;
    obj2->parent = parent;
}

void
PySelectionProperties_SetDefaults(const SelectionProperties *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new SelectionProperties(*atts);
}

